﻿using AutoMapper;

namespace GroceryPriceBook.Core.Mappers
{
	/// <summary>
	/// View Model object for presentation which inherits the AutoMapper Profile class
	/// </summary>
	public class Product : Profile
	{
		public override string ProfileName
		{
			get { return "ProductMappings"; }
		}

		protected override void Configure()
		{
			Mapper.CreateMap<Model.Product, ViewModel.Product>()
				  .ForMember(dest => dest.ProductManufacturerId, opt => opt.MapFrom(src => src.Manufacturer))
				  .ForMember(dest => dest.CategoryId, opt => opt.MapFrom(src => src.Category))
				  .ForMember(dest => dest.AmountUnitId, opt => opt.MapFrom(src => src.AmountUnit))
				  .ForMember(dest => dest.QuantityUnitId, opt => opt.MapFrom(src => src.QuantityUnit))
				  .ForMember(dest => dest.ProductManufacturer, opt => opt.MapFrom(src => src.ProductMaker));
			Mapper.CreateMap<ViewModel.Product, Model.Product>()
				  .ForMember(dest => dest.Manufacturer, opt => opt.MapFrom(src => src.ProductManufacturerId))
				  .ForMember(dest => dest.Category, opt => opt.MapFrom(src => src.CategoryId))
				  .ForMember(dest => dest.AmountUnit, opt => opt.MapFrom(src => src.AmountUnitId))
				  .ForMember(dest => dest.QuantityUnit, opt => opt.MapFrom(src => src.QuantityUnitId))
				  .ForSourceMember(src => src.ProductManufacturer, opt => opt.Ignore())
				  .ForSourceMember(src => src.ProductCategory, opt => opt.Ignore())
				  .ForSourceMember(src => src.ProductAmountUnit, opt => opt.Ignore())
				  .ForSourceMember(src => src.ProductQuantityUnit, opt => opt.Ignore())
				  .ForSourceMember(src => src.ProductCategorySelectListItems, opt => opt.Ignore())
				  .ForSourceMember(src => src.ProductManufacfurerSelectListItems, opt => opt.Ignore())
				  .ForSourceMember(src => src.ProductAmountUnitSelectListItems, opt => opt.Ignore())
				  .ForSourceMember(src => src.ProductQuantityUnitSelectListItems, opt => opt.Ignore())
				  .ForSourceMember(src => src.PurchaseLogItems, opt => opt.Ignore());
		}
	}
}
